package com.demomaster.quickcompat.service;

import android.view.View;
import android.view.WindowManager;

import java.io.Serializable;

public class ViewPositionInfo implements Serializable {
    //private WindowManager.LayoutParams layoutParams;
    private View view;
    private float x;
    private float y;
    private int width;
    private int height;

    public ViewPositionInfo(View view) {
        if(view != null) {
            this.view = view;
            WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) view.getLayoutParams();
            if(layoutParams!=null) {
                this.width = layoutParams.width;
                this.height = layoutParams.height;
                this.x = layoutParams.x;
                this.y = layoutParams.y;
            }
        }
    }

    public ViewPositionInfo(View view,WindowManager.LayoutParams layoutParams){
        this.view = view;
        this.view.setLayoutParams(layoutParams);
        this.width = layoutParams.width;
        this.height = layoutParams.height;
        this.x = layoutParams.x;
        this.y = layoutParams.y;
    }

//    public WindowManager.LayoutParams getLayoutParams() {
//        return layoutParams;
//    }

//    public void setLayoutParams(WindowManager.LayoutParams layoutParams) {
//        this.layoutParams = layoutParams;
//    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }

    public View getView() {
        return view;
    }

    public void setView(View view) {
        this.view = view;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void update() {
       this.width = view.getLayoutParams().width;
        this.height = view.getLayoutParams().height;
        this.x = ((WindowManager.LayoutParams)view.getLayoutParams()).x;
        this.y = ((WindowManager.LayoutParams)view.getLayoutParams()).y;
    }
}
